Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The interpret npm package is designed to be a dictionary of require extensions and associated file extensions. It allows developers to automatically register the appropriate require extension for files based on their file extensions. This is particularly useful when working with different types of files that need to be required in Node.js applications, such as .coffee, .ts, or .jsx files.
Registering require extensions
This code retrieves the require extension for TypeScript files, allowing Node.js to understand how to process and import .ts files.
require('interpret').extensions['.ts']
Associating file extensions with custom handlers
This code demonstrates how to associate a custom file extension (.custom) with a custom compiler or handler to be used when requiring files with that extension.
var interpret = require('interpret');
var extensions = interpret.extensions;
extensions['.custom'] = require('my-custom-compiler');
Rechoir is a package that allows you to automatically register the appropriate require hooks based on a file's extension. It is similar to interpret but goes a step further by actually attempting to require the necessary module to handle the file extension.
Liftoff is a CLI framework that builds on top of interpret. It enables applications to specify which interpreters they support for configuration files, and it will automatically require the necessary dependencies.
This package is used to hook into the require function to add support for transpiling files on the fly. It is similar to interpret in that it deals with require extensions, but it focuses more on the runtime aspect of transpiling or processing files.
A dictionary of file extensions and associated module loaders.
This is used by Liftoff to automatically require dependencies for configuration files, and by rechoir for registering module loaders.
Map file types to modules which provide a require.extensions loader.
{
'.babel.js': {
module: 'babel/register',
register: function (module) {
module({
// register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
// which only captures the final extension (.babel.js -> .js)
extensions: '.js'
})
}
},
'.cirru': 'cirru-script/lib/register',
'.cjsx': 'node-cjsx/register',
'.co': 'coco',
'.coffee': ['coffee-script/register', 'coffee-script'],
'.coffee.md': ['coffee-script/register', 'coffee-script'],
'.csv': 'require-csv',
'.eg': 'earlgrey/register',
'.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
'.iced.md': 'iced-coffee-script/register',
'.ini': 'require-ini',
'.js': null,
'.json': null,
'.json5': 'json5/lib/require',
'.jsx': [
{
module: 'babel/register',
register: function (module) {
module({
extensions: '.jsx'
});
},
},
{
module: 'node-jsx',
register: function (module) {
module.install({
extension: '.jsx',
harmony: true
});
}
}
],
'.litcoffee': ['coffee-script/register', 'coffee-script'],
'.liticed': 'iced-coffee-script/register',
'.ls': ['livescript', 'LiveScript'],
'.node': null,
'.toml': {
module: 'toml-require',
register: function (module) {
module.install();
}
},
'.ts': ['typescript-node/register', 'typescript-register', 'typescript-require'],
'.tsx': ['typescript-node/register'],
'.wisp': 'wisp/engine/node',
'.xml': 'require-xml',
'.yaml': 'require-yaml',
'.yml': 'require-yaml'
};
Same as above, but only include the extensions which are javascript variants.
Consumers should use the exported extensions
or jsVariants
object to determine which module should be loaded for a given extension. If a matching extension is found, consumers should do the following:
If the value is null, do nothing.
If the value is a string, try to require it.
If the value is an object, try to require the module
property. If successful, the register
property (a function) should be called with the module passed as the first argument.
If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
FAQs
A dictionary of file extensions and associated module loaders.
The npm package interpret receives a total of 8,021,336 weekly downloads. As such, interpret popularity was classified as popular.
We found that interpret demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.